<template>
    <div>
        <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>

         <el-card>
             <el-row :gutter="20">
                  <el-col :span="10">
                      <!-- 搜索 -->
                    <el-input  v-model="queryinfo.query" clearable @clear="getOrderList" >
                        <el-button slot="append" icon="el-icon-search" @click="getOrderList" ></el-button>
                    </el-input>
                  </el-col>
           </el-row>
             <el-table :data="orderList" border stripe>
                 <el-table-column type="index"></el-table-column>
                 <el-table-column label="订单编号" prop="order_number"></el-table-column>
                 <el-table-column label="订单价格" prop="order_price" width="120"></el-table-column>
                 <el-table-column label="是否付款" prop="order_pay"  width="120">
                     <template slot-scope="scope">
                         <el-tag type="success" v-if="scope.row.order_pay == 1">已付款</el-tag>
                        <el-tag type="danger" v-else>未付款</el-tag>
                     </template>
                 </el-table-column>
                 <el-table-column label="下单时间" prop="create_time">
                      <template slot-scope="scope">
                        {{scope.row.create_time | dateFormat}}
                        </template>
                 </el-table-column>
                 <el-table-column label="是否发货" prop="is_send"  width="120"></el-table-column>
                 <el-table-column label="操作"  >
                     <template slot-scope="scope">
                         <el-button type="primary" size="mini"  icon="el-icon-edit" @click="showEditDialog(scope.row)">地址修改</el-button>
                         <el-button type="success" size="mini" icon="el-icon-setting" @click="showprogress ">物流查询</el-button>
                     </template>
                 </el-table-column>
             </el-table>
           <!-- 分页 -->
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="queryinfo.pagenum"
              :page-sizes="[5,10, 20, 30, 50,100]"
              :page-size="100"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total" background>
            </el-pagination>
         </el-card>

          <el-dialog
        title="修改地址"
        :visible.sync="editDialogVisible"
        width="50%" @close = 'editDialogClose'>
        <!-- 内容主体区域 -->
            <el-form :model="addrForm" :rules="addrFormRules" ref="addrFormRef" label-width="100px">
                <el-form-item label="省市县" prop="address1">
                     <el-cascader  v-model="addrForm.address1"    :options="cityData"
                            :props="{ expandTrigger: 'hover' }"
                            @change="handleChange">
                            </el-cascader>
                      <!-- <el-input  v-model="addrForm.address1"  prefix-icon='el-icon-s-home'></el-input> -->
                </el-form-item>

                <el-form-item  prop="address2" label="详细地址" >         
                     <el-input v-model="addrForm.address2" clearable  prefix-icon='el-icon-info'></el-input>
                </el-form-item>
            </el-form>
            
        <!-- 内容底部区域 -->
        <span slot="footer" class="dialog-footer">
            <el-button @click="editDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="editUserInfo">确 定</el-button>
        </span>
    </el-dialog>

    <!-- 物流查询对话框 -->
          <el-dialog  title="物流进度"  :visible.sync="ProgressVisle" width="50%"  >
        <!-- 内容主体区域 -->
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="ProgressVisle = false">取 消</el-button>
            <el-button type="primary" @click="progressInfo">确 定</el-button>
        </span>
    </el-dialog>
    </div>
</template>

<script>
import cityData from './citydata.js'
export default {

    data(){
        return{
            queryinfo:{
                query:'',
                pagenum:1,
                pagesize:10
            },
            total:0,
            orderList:[],
            editDialogVisible:false,
            ProgressVisle:false,
            progressData:[],
            cityData,
            orderInfo:{},
            addrForm:{
                address1:[],
                address2:''
            },
            addrFormRules:{
                 address1:[
                      { required: true, message: '请选择省市县', trigger: 'blur' },
                 ],
                address2:[
                     { required: true, message: '请输入详细地址', trigger: 'blur' },
                    { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
                ]
            }
        }
    },
    created(){
        this.getOrderList()
    },
    methods:{
        async  getOrderList(){
            const {data:res} = await this.$http.get('orders',{
                params:this.queryinfo
            })
            if(res.meta.status !== 200 ) return this.$Message.error('订单列表数据请求失败')
            this.orderList = res.data.goods ;
                this.total =  res.data.total
                console.log(this.orderList);
            this.$Message.success('订单列表数据请求成功')

        },
        handleSizeChange(newsize){
                this.queryinfo.pagesize= newsize
                this.getOrderList()
        },
        handleCurrentChange(pagenum){
                this.queryinfo.pagenum =pagenum
                this.getOrderList()
        },
        // 修改地址对话框
        showEditDialog(orderinfo){
            this.editDialogVisible = true;
            this.orderInfo = orderinfo
            console.log( this.orderInfo );
        },
        editDialogClose(){
            this.$refs.addrFormRef.resetFields();
        },
        editUserInfo(){
            //    this.$refs.addrFormRef.validate(async valid=>{
            //        const {data:res} = await this.$http.put(`orders/${orderinfo.order_id}`)
            //         if(res.meta.status !== 200 ) return this.$Message.error('数据获取失败')
            //         this.editForm = res.data
            //   })
             this.editDialogVisible = false;
        },
        handleChange(){
           
            console.log(orderinfo);
            console.log(this.addrForm.address1);
        },
     async showprogress(){
           this.ProgressVisle = true;
        // const {data:res} = await this.$http.get(`kuaidi/1106975712662`)
        // // if(res.meta.status !== 200 ) return this.$Message.error('物流获取失败')
        // this.progressData = res.data
        // console.log(res);
        //      return this.$Message.success('物流获取成功')
              
        },
        progressInfo(){
            this.ProgressVisle =false
        }
    }
   
    
}
</script>

<style lang="less" scoped>
.el-card  {
    margin:10px 0px;
    box-shadow: 0 0 3px #ddd;
}
.el-breadcrumb{
    margin-bottom:15px;
}
.el-button{
    padding: 10px 7px;
    margin:0 10px
}
.el-table,.el-pagination{
    margin-top: 15px;
}
</style>